<!DOCTYPE  HTML>
<html>
	<head>
		
		<script type="text/javascript" src="../resources/script.js"></script>
		<meta charset="utf-8">
  		<meta name="viewport" content="width=device-width, initial-scale=1">
  		<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  		<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  		<link rel="stylesheet" href="../resources/style.css" />
	</head>
	<body>
		<?php
			foreach (glob("../model/*.php") as $filename)
                	{
                        	include_once $filename;
                	}

                	foreach (glob("../dao/*.php") as $filename)
                	{
                        	include_once $filename;
                	}
			
			if(array_key_exists('assign_sessn', $_POST))
			{
				$user_sessndao = new UserSessionDAOImpl();
				$req_list      = $_POST['assign_sessn'];

				foreach($req_list as $str)
				{
					$arr = explode('.', $str);
					$user_sessn = new UserSession($arr[0], $arr[1], UserSession::PENDING);

					$user_sessndao->saveOrUpdate($user_sessn);
				}
												
			}
			
		?>
		<div id="ahmainpnl" >
			<img id="ahlogo" src="../resources/logo.png"></img>
			<div id="ahheaderpnl">
				
			<p id="hSess">Session Information</p>
			</div>
			<div id="ahmenupnl">
				 <a href="home_admin.php" id="ahbtnhome" class="btn btn-success">Home</a>
				<!--button type="button" id="ahbtnhome" class="btn btn-success" onclick="window.open('home_admin.html')">Home</button-->
				<hr/>
				<a href="addUser.php" id="ahbtnhome" class="btn btn-info">Users</a>
				<!--button type="button" id="ahbtnuser" class="btn btn-info" onclick="window.open('addUser.html')">Users</button-->
				<a href="addTechnology.php" id="ahbtnhome" class="btn btn-info">Technologies</a>
				<!--button type="button" id="ahbtntech" class="btn btn-info" onclick="window.open('addTechnology.html')">Technologies</button-->
				<a id="ahbtnlogout" href="../login.html">Logout</a>
			</div>
			<div  class="container" id="ahcontentpnl"><br>
			<div class="container" id="ahses_info">
  
         
<table id="ses_info" style="width: 45%; float: left;">

	<tr>
		<td>ID :</td>
		<td>
			<?php 
				$id = $_GET['sess_id'];

				print $id;
			?>
		</td>
		</tr>
	    <tr>
	    <td>Name :</td>
		<td> 
			<?php
				$sessdao = new SessionDAOImpl();

				$sessn = $sessdao->getSession($id);

				print $sessn->getSessionName($id);
			?>
		</td>
	</tr>
	<tr>	
		<td>Technology :</td>
		<td>
			<?php
				$tech_id = $sessn->getTechId();
				$techdao = new TechnologyDAOImpl();

				print $techdao->getNameFromId($tech_id);
			?>
		</td>
		</tr>
		<tr>
 		<td>Trainer Name :</td>
		<td>
			<?php
				print $sessn->getTrainer();
			?>
		</td>
	</tr>	
	<tr>	<td>Date :</td>
		<td>
			<?php
				print date('Y-m-d' , $sessn->getStartDateTime());
			?>
		</td>
		</tr>
		<tr>
		<td>Time :</td>
		<td>
			<?php
                                print date('H:i:s' , $sessn->getStartDateTime());
                        ?>

		</td>
	</tr>
	<tr>
		<td>Status :</td>
		<td>
			<?php
				print $sessn->getStatus();
			?>
		</td>
		
	</tr>

</table>
	<div class="container" id="ahses_user" style="width: 45%; float: left;">
	
    <table class="table" >
    <caption>Trainee Assigned</caption>	
    <thead>
    <tr>
        <th>UserId</th>
        <th>Name</th>
        <th>Status</th>
	<th>Comment</th>
      </tr>
    </thead>
    <tbody>
	<?php
		$conn = new mysqli('localhost', 'root', 'root123', 'tms');

		$sql = "select Profile.user_id, concat(first_name,'.',last_name) as name, status, reason from User, Profile, Training_Session, User_Session where User.user_id = User_Session.user_id and Training_Session.sess_id = User_Session.sess_id and Training_Session.sess_id=$id and Profile.user_id = User.user_id";

		$res = $conn->query($sql);
		if($res->num_rows != 0)
		{
			while($row = $res->fetch_assoc())
			{
				if($row['status'] == 'accepted')
				{
	?>
			
      <tr class="success">
        <td><?php print $row['user_id']; ?></td>
        <td><?php print $row['name']; ?></td>
        <td><?php print $row['status']; ?></td>
	<td><?php print $row['reason']; ?></td>
      </tr>
	<?php			}
				elseif($row['status'] == 'rejected')
				{
	?>
      <tr class="danger">
        <td><?php print $row['user_id']; ?></td>
        <td><?php print $row['name']; ?></td>
        <td><?php print $row['status']; ?></td>
        <td><?php print $row['reason']; ?></td>
      </tr>
	<?php
				}
				else
				{
	?>
      <tr class="info">
        <td><?php print $row['user_id']; ?></td>
        <td><?php print $row['name']; ?></td>
        <td><?php print $row['status']; ?></td>
        <td><?php print $row['reason']; ?></td>
      </tr>
	<?php
				}
			}
		}
		else
		{
			echo "No trainees assigned for this session";
		}
	?>
    </tbody>
  </table>
</div>
					
</div>		
					
  					<button id="btnaddSessionUsers" type="button"  class="btn btn-primary" data-toggle="collapse" class="adbtns" data-target="#addUsers">
						Add Trainees
					</button>  		
  					<div id="addUsers" class="collapse container">

  					<form action='' method='POST'>				
  					<table class="table" style="overflow-y: scroll">
    						<thead>
      							<tr>
								<th></th>
        							<th>ID</th>
            							<th>Emp-ID</th>
								<th>Name</th>
								<th>DOB</th>
								<th>Joining Date</th>
								<th>College</th>
							</tr>
     
    						</thead>
    						<tbody>
							<?php
								$conn = new mysqli('localhost', 'root', 'root123', 'tms');

								$sql  = "select Profile.user_id, User.emp_id, concat(first_name,'.',last_name) as name, DATE_FORMAT(dob, '%d-%m-%Y') as DOB, DATE_FORMAT(doj, '%d-%m-%Y') as DOJ, college from Profile, User where Profile.user_id not in (select User.user_id from User, Training_Session, User_Session where User.user_id = User_Session.user_id and Training_Session.sess_id = User_Session.sess_id and Training_Session.on_date = '".date('Y-m-d', $sessn->getStartDateTime())."' and Training_Session.sess_status = 'available' or Training_Session.sess_status = 'pending') and Profile.user_id = User.user_id";

								$res = $conn->query($sql);

								if($res->num_rows != 0)
								{
									while($row = $res->fetch_assoc())
									{
							?>
							<tr>
								<td class="checkbox"><input type="checkbox" name="assign_sessn[]" value="<?php print $row['user_id'].".".$_GET['sess_id']; ?>" > </td>
								<td><?php print $row['user_id']; ?></td>
            							<td><?php print $row['emp_id']; ?></td>
								<td><?php print $row['name']; ?></td>
								<td><?php print $row['DOB']; ?></td>
								<td><?php print $row['DOJ']; ?></td>
								<td><?php print $row['college']; ?></td>
      							</tr>
      							<?php
									}
								}
								else
								{
									echo "no Trainees available";
								}
							?>
  						</tbody>
  					</table>

  					<button id="btnSaveSes" type="submit"  class="btn btn-primary">
  						Add
  					</button>
  					</form>
  					</div>
 	</div><br><hr><br>
	<div class="divfooter" >
			<p>© 2007-2015 Spring Computing Technologies Pvt. Ltd., All Rights Reserved.</p>
		</div>
	</body>
	
</html>
